<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.net.URL" %>
<%@page import="java.io.*"%>
<%@ page import="com.twarder.struts.action.book.*"%>
<%
	String pageUrl = request.getParameter("url");
	String filters = request.getParameter("filters");
	String ret = "";
	String errSign = ":(error):";
	String _charSet = request.getSession().getAttribute("charset").toString();
	StringBuffer is = new StringBuffer();
	EBook book = new EBook("");
	String[] filtersArr = filters.split("--");
	for(int i=0;i<filtersArr.length;i++){
		String[] filter = filtersArr[i].split(",");
		book.addFilter(filter[0],filter[1],filter[2],filter[3]);
	}
	ArrayList<String> filter = book.getFilters(); 
	if (filter != null){
		try {
			URL U = new URL(pageUrl);
			BufferedReader br = new BufferedReader(new InputStreamReader(U.openStream(), _charSet));
			String s = "";
			while ((s = br.readLine()) != null) {
				is.append(s);
			}
			br.close();
			String webPageSourceCode = is.toString();

			ArrayList<String> htmlContentOnePage = book.getHtmlContentByFilters(webPageSourceCode, filter); 
			for (int j = 0; j < htmlContentOnePage.size(); j++) {
				ret += "\r" + book.getPureContent(htmlContentOnePage.get(j)) + "\r"; 
			}
		}catch (Exception e) {
			ret = errSign + pageUrl;
		}
	}
	out.println(ret);
%>
